type User = {
  id?: number,
  name: string,
}
type Animal = {
  id?: number,
  name: string,
}
type AdminUser = {
  id?: number,
  name: string,
  role: string,
}

type ExistUser = {
  id: number,
  name: string
}
type LegacyUser = {
  id?: number | string,
  name: string
}

const u2:ExistUser = {
  id: 2,
  name: "user2"
}

const u3:LegacyUser = {
  id: 3,
  name: "user3"
}

function deleteUser(user: User) { console.log(user) }

const a1: Animal = {
  id: 1,
  name: 'animal1'
}

const u1: AdminUser = {
  id: 2,
  name: 'user2',
  role: 'admin'
}

deleteUser(a1); // OK? Error?
deleteUser(u1); // OK? Error?
deleteUser(u2);
// deleteUser(u3);  

// User ---> id ---> number | undefined
// ExistUser ---> id ---> number
// LegacyUser ---> id ---> number | string | undefined

// ExistUser <: User <: LegacyUser

type Pet = {
  name:string
}

type Dog = Pet & {
  breed: string
}

const dogs: Dog[] = [
  {
    name: "jack",
    breed: "拉布拉多"
  },
  {
    name: "rose",
    breed: "吉娃娃"
  }
]

const pet: Pet[] = dogs;

type Arrs<T> = {
  arr: T[]
}

const arr1: Arrs<Dog> = {
  arr: dogs
}

const arr2: Arrs<Pet> = arr1;